<template>
	<view>
		<z-nav-bar backState="1000">用户登录</z-nav-bar>
		
		<view class="text-center u-p-30" style="margin-top: 200rpx;">
			<image src="../../static/logo.png" class="logo-size"></image>
			<!-- <template v-if="env != 'production'"> -->
				<view class="u-p-t-80">
					<u-button v-if="!isShowPrivacy" open-type="getPhoneNumber" :customStyle="{'color':'#FFFFFF', 'backgroundColor':'#FFB143'}" size="medium" shape="circle" @getphonenumber="getPhoneNumber">
						<view class="u-flex">
							<!-- <u-icon name="weixin-fill" size="20" color="#FFFFFF"></u-icon> -->
							<text class="u-p-l-20">手机号快捷登录</text>
						</view>
					</u-button>
					<u-button v-else :customStyle="{'color':'#FFFFFF', 'backgroundColor':'#FFB143'}" size="medium" shape="circle" @click="handleWechatLogin">
						<view class="u-flex">
							<u-icon name="weixin-fill" size="20" color="#FFFFFF"></u-icon>
							<text class="u-p-l-20">手机号快捷登录</text>
						</view>
					</u-button>
				</view>
				<!-- #ifdef H5 -->
				<view class="u-p-t-30" @click="handlePhoneLogin">
					<text style="opacity: 0.5;">短信验证登录</text>
				</view>			
				<!-- #endif -->	
		</view>
	</view>
</template>

<script>
	import {jumpTypeEnum} from '@/common/const.js'
	import {getPhone} from '@/api/login.js'
	
	export default{
		data(){
			return{
				isShowPrivacy:false,
				targetType:null,
				params:null
			}
		},
		onLoad(e) {
			// if(e.targetType){
			// 	console.log('1111')
			// 	this.targetType = e.targetType
			// }
			
			// if(e.params){
			// 	this.params = JSON.parse(decodeURIComponent(e.params))
			// }
			// console.log(this.targetType)
			// console.log(this.params)
		},
		methods:{
			
			/**
			 * 微信手机号授权
			 */
			getPhoneNumber(e){
				// #ifdef MP-WEIXIN
				// 拒绝的场合
				if(!e.detail.code)
					return
					
				// 对接接口
				getPhone(e.detail.code).then(res=>{
					const data = {
						mobile:res.data,
					}
					// 授权登录
					this.$store.dispatch("loginAuth", data).then(res=>{
						console.log('登录成功')
						// uni.$emit("reloadShareMenuStatus")
						// console.log(this.targetType)
						// if(this.targetType){
						// 	console.log('1')
						// 	if(this.targetType == 'home'){
						// 		this.jumpUtil.jumpTo(jumpTypeEnum.reLaunch, '/pages/home/index', false)
						// 	} else if (this.targetType == 'goodsDetail'){
						// 		this.jumpUtil.jumpTo(jumpTypeEnum.redirect, `/pages_one/goods/detail?${this.params}`, false)
						// 	}							
						// } else {
						// 	console.log('2')
						// 	uni.navigateBack()
						// }
						uni.navigateBack()
					})
				})
				// #endif				
			},
			
			/**
			 * 短信验证码登录
			 */
			handlePhoneLogin(){
				this.jumpUtil.jumpTo(jumpTypeEnum.navigate, `/pages_one/login/sms/index?targetUrl=${this.targetUrl}`, false)
			}
		}
	}
</script>


<style>
	page{
		background-color: #FFFFFF;
	}
</style>

<style lang="scss" scoped>
	
	.agreement {
		display: flex;
		align-items: center;
		 justify-content: center;
		margin: 0rpx 0rpx;
		margin-top: 50rpx;
		
		.agreement-text {
			font-size: 26rpx;
			padding-left: 0rpx;
			color: $u-tips-color;
			
			.protocol{
				color: #006EFF;
			}
		}
	}
	
	.logo-size{
		width: 150rpx;
		height: 150rpx;
	}
</style>